<template>
  <el-dialog
    :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form label-position="left" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="名称"></el-input>
    </el-form-item>

    <el-form-item label="1、开房后" prop="minute" >
      <el-input style="width: 70px;" v-model="dataForm.minute" placeholder="分钟"></el-input>
      分钟内按
      <el-input style="width: 70px;"  v-model="dataForm.price" placeholder="价格"></el-input>
      元收取
    </el-form-item>
    <el-form-item label="2、超时之后每" prop="perNMin" >
      <el-input style="width: 70px;"  v-model="dataForm.perNMin" placeholder="分钟"></el-input>
      分钟收取
      <el-input style="width: 70px;"  v-model="dataForm.perNMinPrice" placeholder="满多少分钟收取"></el-input>
      元，不足
      <el-input style="width: 70px;"  v-model="dataForm.perNMin" placeholder="分钟"></el-input>
      分钟，超过
      <el-input style="width: 70px;"  v-model="dataForm.moreThanNMin" placeholder="超过分钟"></el-input>
      分钟加收
      <el-input style="width: 70px;"  v-model="dataForm.moreThanNPrice" placeholder="超过多少分钟收取"></el-input>
      元
    </el-form-item>
    <el-form-item label="3、封顶"  prop="upperPirce">
      <el-input style="width: 70px;"  v-model="dataForm.upperPirce" placeholder="封顶价格"></el-input>
      元封顶 注意：0元视为不封顶
    </el-form-item>
    <el-form-item label="4、消费超过"  prop="toBeDayRoomMin">
      <el-input style="width: 70px;"  v-model="dataForm.toBeDayRoomMin" placeholder="分钟"></el-input>
      分钟，自动转为全天房 注意：0分钟视为不自动转全天房
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          name: '',
          createTime: '',
          updateTime: '',
          minute: 60,
          price: 0,
          perNMin: 60,
          perNMinPrice: 0,
          moreThanNMin: 20,
          moreThanNPrice: 0,
          upperPirce: 0,
          toBeDayRoomMin: 0
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          minute: [
            { required: true, message: '分钟不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '价格不能为空', trigger: 'blur' }
          ],
          perNMin: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          perNMinPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          moreThanNMin: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          moreThanNPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          upperPirce: [
            { required: true, message: '封顶价格不能为空', trigger: 'blur' }
          ],
          toBeDayRoomMin: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomhours/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tHotelFloorRoomHours.sellerId
                this.dataForm.name = data.tHotelFloorRoomHours.name
                this.dataForm.createTime = data.tHotelFloorRoomHours.createTime
                this.dataForm.updateTime = data.tHotelFloorRoomHours.updateTime
                this.dataForm.minute = data.tHotelFloorRoomHours.minute
                this.dataForm.price = data.tHotelFloorRoomHours.price
                this.dataForm.perNMin = data.tHotelFloorRoomHours.perNMin
                this.dataForm.perNMinPrice = data.tHotelFloorRoomHours.perNMinPrice
                this.dataForm.moreThanNMin = data.tHotelFloorRoomHours.moreThanNMin
                this.dataForm.moreThanNPrice = data.tHotelFloorRoomHours.moreThanNPrice
                this.dataForm.upperPirce = data.tHotelFloorRoomHours.upperPirce
                this.dataForm.toBeDayRoomMin = data.tHotelFloorRoomHours.toBeDayRoomMin
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomhours/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'name': this.dataForm.name,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'minute': this.dataForm.minute,
                'price': this.dataForm.price,
                'perNMin': this.dataForm.perNMin,
                'perNMinPrice': this.dataForm.perNMinPrice,
                'moreThanNMin': this.dataForm.moreThanNMin,
                'moreThanNPrice': this.dataForm.moreThanNPrice,
                'upperPirce': this.dataForm.upperPirce,
                'toBeDayRoomMin': this.dataForm.toBeDayRoomMin
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
@media (max-width: 1500px) {
  .el-dialog__wrapper /deep/ .el-dialog {
    width: 70%;
  }
}
</style>
